﻿//-----------------------------------------------------------------
//
// @(#)$Id: ProductDetail.aspx.cs,v 1.0 2013/12/13 17:33:16 lichunhua Exp $
// @(#)$Author: lichunhua  $
// @(#)$Date: 2013/12/13 17:33:16 $
// @(#)$Description:
//
//
//
//                 All Rights Reserved.
//-----------------------------------------------------------------
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using ebay.Dal.CenterDB_BasTableAdapters;
using ebay.Dal.CenterDB_EbayTableAdapters;
using ebay.Dal.K3DataBaseTableAdapters;

public partial class UI_Bas_ProductDetail : System.Web.UI.Page
{
    void BindDropDownList()
    {
        T_EbayConditionTableAdapter conditionAdapter = new T_EbayConditionTableAdapter();
        ddlConditionId.DataSource = conditionAdapter.GetData();
        ddlConditionId.DataTextField = "ConditionName";
        ddlConditionId.DataValueField = "ConditionId";
        ddlConditionId.DataBind();

        T_SubMessageTableAdapter subMessageAdapter = new T_SubMessageTableAdapter();

        //销售状态
        ddlSalesStatus.DataSource = subMessageAdapter.GetDataByFTypeId(10002);
        ddlSalesStatus.DataTextField = "FName";
        ddlSalesStatus.DataValueField = "FItemID";
        ddlSalesStatus.DataBind();

        //包裹类型
        ddlPackageType.DataSource = subMessageAdapter.GetDataByFTypeId(10008);
        ddlPackageType.DataTextField = "FName";
        ddlPackageType.DataValueField = "FItemID";
        ddlPackageType.DataBind();

        //质保期        
        ddlWarrantyDays.DataSource = subMessageAdapter.GetDataByFTypeId(10003);
        ddlWarrantyDays.DataTextField = "FName";
        ddlWarrantyDays.DataValueField = "FItemID";
        ddlWarrantyDays.DataBind();

        //发货方式
        ddlDeliveryId.DataSource = subMessageAdapter.GetDataByFTypeId(32);
        ddlDeliveryId.DataTextField = "FName";
        ddlDeliveryId.DataValueField = "FItemID";
        ddlDeliveryId.DataBind();


        //使用状态
        ddlUseStatusId.DataSource = subMessageAdapter.GetDataByFTypeId(170);
        ddlUseStatusId.DataTextField = "FName";
        ddlUseStatusId.DataValueField = "FItemID";
        ddlUseStatusId.DataBind();

        //计价方法
        ddlValuationMethod.DataSource = subMessageAdapter.GetDataByFTypeId(200);
        ddlValuationMethod.DataTextField = "FName";
        ddlValuationMethod.DataValueField = "FItemID";
        ddlValuationMethod.DataBind();

        //售卖方式
        ddlSalesMode.DataSource = subMessageAdapter.GetDataByFTypeId(648);
        ddlSalesMode.DataTextField = "FName";
        ddlSalesMode.DataValueField = "FItemID";
        ddlSalesMode.DataBind();

        //是否缺货
        ddlIsOutOfStock.DataSource = subMessageAdapter.GetDataByFTypeId(10001);
        ddlIsOutOfStock.DataTextField = "FName";
        ddlIsOutOfStock.DataValueField = "FItemID";
        ddlIsOutOfStock.DataBind();

        //是否新品
        ddlIsNew.DataSource = subMessageAdapter.GetDataByFTypeId(10006);
        ddlIsNew.DataTextField = "FName";
        ddlIsNew.DataValueField = "FItemID";
        ddlIsNew.DataBind();


        //新品状态 
        ddlNewProductStatus.DataSource = subMessageAdapter.GetDataByFTypeId(10007);
        ddlNewProductStatus.DataTextField = "FName";
        ddlNewProductStatus.DataValueField = "FItemID";
        ddlNewProductStatus.DataBind();
        T_MeasureUnitTableAdapter measureAdapter = new T_MeasureUnitTableAdapter();

        DataTable unitsSource = measureAdapter.GetData();
        //基本计量单位
        ddlBaseUnit.DataSource = unitsSource;
        ddlBaseUnit.DataTextField = "FName";
        ddlBaseUnit.DataValueField = "FMeasureUnitID";
        ddlBaseUnit.DataBind();

        //采购计量单位
        ddlPurUnit.DataSource = unitsSource;
        ddlPurUnit.DataTextField = "FName";
        ddlPurUnit.DataValueField = "FMeasureUnitID";
        ddlPurUnit.DataBind();

        //销售计量单位
        ddlSalesUnit.DataSource = unitsSource;
        ddlSalesUnit.DataTextField = "FName";
        ddlSalesUnit.DataValueField = "FMeasureUnitID";
        ddlSalesUnit.DataBind();

        //生产计量单位
        ddlProduceUnit.DataSource = unitsSource;
        ddlProduceUnit.DataTextField = "FName";
        ddlProduceUnit.DataValueField = "FMeasureUnitID";
        ddlProduceUnit.DataBind();

        //库存计量单位
        ddlStoreUnit.DataSource = unitsSource;
        ddlStoreUnit.DataTextField = "FName";
        ddlStoreUnit.DataValueField = "FMeasureUnitID";
        ddlStoreUnit.DataBind();

        //条码标签打印单位
        ddlLableUnit.DataSource = unitsSource;
        ddlLableUnit.DataTextField = "FName";
        ddlLableUnit.DataValueField = "FMeasureUnitID";
        ddlLableUnit.DataBind();
        T_vwUnitGroupTableAdapter unitGroupAdapter = new T_vwUnitGroupTableAdapter();
        ddlMeasureUnitsGroup.DataSource = unitGroupAdapter.GetData();
        ddlMeasureUnitsGroup.DataTextField = "Fname";
        ddlMeasureUnitsGroup.DataValueField = "FitemId";
        ddlMeasureUnitsGroup.DataBind();

        //商品类型
        ddlProductType.DataSource = subMessageAdapter.GetDataByFTypeId(647);
        ddlProductType.DataTextField = "FName";
        ddlProductType.DataValueField = "FItemID";
        ddlProductType.DataBind();


        T_AccountTableAdapter accountAdapter = new T_AccountTableAdapter();
        DataTable accountSource = accountAdapter.GetData();

        //存货科目代码
        ddlStockSubjectId.DataSource = accountSource;
        ddlStockSubjectId.DataTextField = "FName";
        ddlStockSubjectId.DataValueField = "FItemId";
        ddlStockSubjectId.DataBind();

        //销售收入科目代码
        ddlSalesSubjectId.DataSource = accountSource;
        ddlSalesSubjectId.DataTextField = "FName";
        ddlSalesSubjectId.DataValueField = "FItemId";
        ddlSalesSubjectId.DataBind();


        //销售收入科目代码
        ddlSalesCostSubjectId.DataSource = accountSource;
        ddlSalesCostSubjectId.DataTextField = "FName";
        ddlSalesCostSubjectId.DataValueField = "FItemId";
        ddlSalesCostSubjectId.DataBind();

        //发货仓库
        T_StockTableAdapter stockAdapter = new T_StockTableAdapter();
        ddlDeliveryWarehouseId.DataSource = stockAdapter.GetData();
        ddlDeliveryWarehouseId.DataTextField = "FName";
        ddlDeliveryWarehouseId.DataValueField = "FItemId";
        ddlDeliveryWarehouseId.DataBind();

        T_EbayCategoryTableAdapter categoryAdapter = new T_EbayCategoryTableAdapter();
        ddlFirstCategoryId.DataSource = categoryAdapter.GetFirstLevel(1, 1);
        ddlFirstCategoryId.DataValueField = "CategoryId";
        ddlFirstCategoryId.DataTextField = "CategoryName";
        ddlFirstCategoryId.DataBind();
        ddlFirstCategoryId.Items.Insert(0, new ListItem("<--请选择-->", ""));

        ddlFirstCategoryId.SelectedIndexChanged += new EventHandler(ddlFirstCategoryId_SelectedIndexChanged);
        ddlTwoCategoryId.SelectedIndexChanged += new EventHandler(ddlTwoCategoryId_SelectedIndexChanged);
    }

    void ddlTwoCategoryId_SelectedIndexChanged(object sender, EventArgs e)
    {
        string parentId = ddlTwoCategoryId.SelectedValue == null ? "" : ddlTwoCategoryId.SelectedValue.ToString();
        if (!string.IsNullOrEmpty(parentId))
        {
            T_EbayCategoryTableAdapter categoryAdapter = new T_EbayCategoryTableAdapter();
            ddlThreeCategoryId.DataSource = categoryAdapter.GetChild(1, 3, parentId);
            ddlThreeCategoryId.DataValueField = "CategoryId";
            ddlThreeCategoryId.DataTextField = "CategoryName";
            ddlThreeCategoryId.DataBind();
            ddlThreeCategoryId.Items.Insert(0, new ListItem("<--请选择-->", ""));
        }
    }

    void ddlFirstCategoryId_SelectedIndexChanged(object sender, EventArgs e)
    {
        string parentId = ddlFirstCategoryId.SelectedValue == null ? "" : ddlFirstCategoryId.SelectedValue.ToString();
        if (!string.IsNullOrEmpty(parentId))
        {
            T_EbayCategoryTableAdapter categoryAdapter = new T_EbayCategoryTableAdapter();
            ddlTwoCategoryId.DataSource = categoryAdapter.GetChild(1, 2, parentId);
            ddlTwoCategoryId.DataValueField = "CategoryId";
            ddlTwoCategoryId.DataTextField = "CategoryName";
            ddlTwoCategoryId.DataBind();
            ddlTwoCategoryId.Items.Insert(0, new ListItem("<--请选择-->", ""));

            ddlThreeCategoryId.Items.Clear();
        }
    }
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        BindDropDownList();
    }
    static string act = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        WebUtility.CheckLogin();
        if (!IsPostBack)
        {
            string productId = Request.QueryString["id"];
            act = Request.QueryString["act"];
            if (!string.IsNullOrEmpty(act))
            {
                act = WebUtility.InputText(act, 1);
                if (act == "e")
                {
                    txtProductId.Attributes["readonly"] = "readonly";
                    T_ProductTableAdapter productAdapter = new T_ProductTableAdapter();
                    DataTable table = productAdapter.GetDataByProductId(productId);
                    if (table.Rows.Count > 0)
                    {
                        DataRow r = table.Rows[0];
                        foreach (Control txtControl in this.form1.Controls)
                        {
                            if (txtControl.ID == "txtCategoryName")
                            {
                                continue;
                            }
                            if (txtControl is HtmlInputText)
                            {
                                HtmlInputText txtBox = (HtmlInputText)txtControl;
                                string colName = txtBox.ID.Remove(0, 3);
                                string val = r[colName].ToString();
                                if (table.Columns[colName].DataType.Name == "DateTime")
                                {
                                    DateTime valDate = DateTime.Parse(val);
                                    DateTime defaultDateTime = new DateTime(1900, 1, 1);
                                    if (valDate == defaultDateTime)
                                    {
                                        val = "";
                                    }
                                }
                                txtBox.Value = val;
                            }
                            else if (txtControl is HtmlSelect)
                            {
                                HtmlSelect ddList = (HtmlSelect)txtControl;
                                string colName = ddList.ID.Remove(0, 3);
                                ddList.Value = r[colName].ToString();

                            }
                            else if (txtControl is HtmlInputHidden)
                            {
                                HtmlInputHidden ddList = (HtmlInputHidden)txtControl;
                                string colName = ddList.ID.Remove(0, 3);
                                ddList.Value = r[colName].ToString();


                            }
                        }
                        string[] parentcategorys = new string[3];
                        string categoryId = r["CategoryId"].ToString();
                        parentcategorys[2] = categoryId;
                        if (!string.IsNullOrEmpty(categoryId))
                        {
                            T_EbayCategoryTableAdapter categoryAdapter = new T_EbayCategoryTableAdapter();
                            object categoryval = categoryAdapter.GetParentByChildId(categoryId);
                            if (categoryval != null && categoryval != DBNull.Value)
                            {
                                parentcategorys[1] = categoryval.ToString();
                                categoryval = categoryAdapter.GetParentByChildId(parentcategorys[1]);
                                if (categoryval != null && categoryval != DBNull.Value)
                                {
                                    parentcategorys[0] = categoryval.ToString();
                                }
                            }
                        }
                        int index = 1;
                        foreach (string cs in parentcategorys)
                        {
                            if (string.IsNullOrEmpty(cs))
                            {
                                continue;
                            }

                            T_EbayCategoryTableAdapter categoryAdapter = new T_EbayCategoryTableAdapter();
                            if (index == 1)
                            {
                                ddlFirstCategoryId.SelectedValue = cs;
                                DataTable tableSource = categoryAdapter.GetChild(1, 2, cs);
                                ddlTwoCategoryId.DataSource = tableSource;
                                ddlTwoCategoryId.DataValueField = "CategoryId";
                                ddlTwoCategoryId.DataTextField = "CategoryName";
                                ddlTwoCategoryId.DataBind();
                                ddlTwoCategoryId.Items.Insert(0, new ListItem("<--请选择-->", ""));
                            }
                            else if (index == 2)
                            {

                                ddlTwoCategoryId.SelectedValue = cs;
                                DataTable tableSource = categoryAdapter.GetChild(1, 3, cs);
                                ddlThreeCategoryId.DataSource = tableSource;
                                ddlThreeCategoryId.DataValueField = "CategoryId";
                                ddlThreeCategoryId.DataTextField = "CategoryName";
                                ddlThreeCategoryId.DataBind();
                                ddlThreeCategoryId.Items.Insert(0, new ListItem("<--请选择-->", ""));
                                ddlThreeCategoryId.SelectedValue = cs;
                            }
                            else if (index == 3)
                            {

                                ddlThreeCategoryId.SelectedValue = cs;
                            }
                            index++;
                        }
                    }
                }
            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Session["UserId"] == null)
        {
            WebUtility.ShowMsg("登陆超时,请重新登陆",this);
            return;
        }
        string userId = Session["UserId"].ToString();
        switch (act)
        {
            case "I":
                {
                    T_ProductTableAdapter productAdapter = new T_ProductTableAdapter();
                    string productId = txtProductId.Value;
                    int val = Convert.ToInt32(productAdapter.ExistsByProductId(productId));
                    if (val > 0)
                    {
                        WebUtility.ShowMsg("物品代码重复,请重新输入后再试一次!", this);
                        return;
                    }

                    string categoryId = "";
                    string categoryId1 = ddlFirstCategoryId.SelectedValue == null ? "" : ddlFirstCategoryId.SelectedValue.ToString();
                    if (!string.IsNullOrEmpty(categoryId1))
                    {
                        categoryId = categoryId1;
                    }
                    string categoryId2 = ddlTwoCategoryId.SelectedValue == null ? "" : ddlTwoCategoryId.SelectedValue.ToString();
                    if (!string.IsNullOrEmpty(categoryId2))
                    {
                        categoryId = categoryId2;
                    }
                    string categoryId3 = ddlThreeCategoryId.SelectedValue == null ? "" : ddlThreeCategoryId.SelectedValue.ToString();
                    if (!string.IsNullOrEmpty(categoryId3))
                    {
                        categoryId = categoryId3;
                    }
                    val = productAdapter.Insert(
                        Convert.ToInt32(string.IsNullOrEmpty(txtFitemId.Value) ? "0" : txtFitemId.Value),
                        txtProductId.Value,
                        txtProductSpecification.Value,
                        txtUserCode.Value, categoryId, "", txtpicUrl.Value, txtDescription.Value, txtProductName.Value, Convert.ToDecimal(txtPackageWidth.Value), Convert.ToDecimal(txtPackageLength.Value),
                        Convert.ToDecimal(txtPackageHeight.Value), Convert.ToDecimal(txtPackageVolume.Value), Convert.ToDecimal(txtPackageWeight.Value), Convert.ToDecimal(txtSpecial_PackageWeight.Value),
                        Convert.ToInt32(ddlIsOutOfStock.Value), Convert.ToInt32(txtSalesLevel.Value), Convert.ToInt32(ddlSalesStatus.Value), txtKeyWords.Value, string.IsNullOrEmpty(txtCheckDateTime.Value) ? new DateTime(1900, 1, 1) : Convert.ToDateTime(txtCheckDateTime.Value),
                        Convert.ToInt32(ddlPackageType.Value), Convert.ToInt32(ddlNewProductStatus.Value), Convert.ToInt32(ddlWarrantyDays.Value), txtCustomsName.Value, txtHSCode.Value, txtInternationalCode.Value,
                        Convert.ToInt32(ddlConditionId.Value), Convert.ToInt32(ddlDeliveryWarehouseId.Value), Convert.ToInt32(ddlDeliveryId.Value), Convert.ToInt32(ddlIsNew.Value),
                        string.IsNullOrEmpty(txtAddDateTime.Value) ? new DateTime(1900, 1, 1) : Convert.ToDateTime(txtAddDateTime.Value), txtDelivery.Value, Convert.ToDecimal(txtExpectedSales.Value),
                        Convert.ToDecimal(txtMinProfit.Value), txtSalesGroup.Value, Convert.ToInt32(ddlMeasureUnitsGroup.Value), Convert.ToInt32(ddlBaseUnit.Value),
                        Convert.ToInt32(ddlPurUnit.Value), Convert.ToInt32(ddlSalesUnit.Value), Convert.ToInt32(ddlProduceUnit.Value), Convert.ToInt32(ddlStoreUnit.Value), Convert.ToInt32(ddlLableUnit.Value),
                        Convert.ToInt32(ddlProductType.Value), Convert.ToInt32(ddlUseStatusId.Value), Convert.ToInt32(ddlSalesMode.Value), Convert.ToInt32(ddlValuationMethod.Value),
                        Convert.ToInt32(ddlStockSubjectId.Value), Convert.ToInt32(ddlSalesSubjectId.Value), Convert.ToInt32(ddlSalesCostSubjectId.Value), Convert.ToDecimal(txtEbayMinPrice.Value),
                        txtEbayMinPriceCountry.Value, Convert.ToDecimal(txtEbayRankMinPrice.Value), Convert.ToDecimal(txtSuggestionPurPrice.Value), Convert.ToDecimal(txtExpectedPurPrice.Value),
                        Convert.ToDecimal(txtExpectedUnitProfit.Value), Convert.ToDecimal(txtExpectedDayOfProfit.Value), string.IsNullOrEmpty(txtExpectedSalesDateTime.Value) ? new DateTime(1900, 1, 1) : Convert.ToDateTime(txtExpectedSalesDateTime.Value),
                        Convert.ToDecimal(txtExpectedWeight.Value), Convert.ToDecimal(txtExpectedPrice.Value), txtRivalItemId.Value, Convert.ToInt32(txtStockLevel.Value), Convert.ToInt32(txtMaxStockDay.Value),
                        Convert.ToDecimal(txtExpectedSalesArg.Value), Convert.ToInt32(txtOrderHandleDay.Value), Convert.ToInt32(txtAllocationDay.Value), Convert.ToDecimal(txtWareHouseSafeArg.Value),
                        Convert.ToDecimal(txtCenterWareHouseSafetyFactor.Value), Convert.ToInt32(txtCenterWareHouseReplenishmentInterval.Value),
                        Convert.ToInt32(txtCenterWareHouseShipInterval.Value), Convert.ToInt32(txtTransitDays.Value), Convert.ToInt32(txtWarningDays.Value),
                        Convert.ToInt32(txtDestWareHouse.Value), Convert.ToInt32(txtTransitWareHouse.Value), "", userId, DateTime.Now, "", new DateTime(1900, 1, 1), 0, 0m, 0m);
                    if (val > 0)
                    {
                        Response.Write("<script>alert('新增成功!');window.location.href='Product.aspx'</script>");
                    }
                }
                break;
            case "e":
                {
                    T_ProductTableAdapter productAdapter = new T_ProductTableAdapter();
                    string productId = txtProductId.Value;
                    int val = 0;
                    string categoryId = "";
                    string categoryId1 = ddlFirstCategoryId.SelectedValue == null ? "" : ddlFirstCategoryId.SelectedValue.ToString();
                    if (!string.IsNullOrEmpty(categoryId1))
                    {
                        categoryId = categoryId1;
                    }
                    string categoryId2 = ddlTwoCategoryId.SelectedValue == null ? "" : ddlTwoCategoryId.SelectedValue.ToString();
                    if (!string.IsNullOrEmpty(categoryId2))
                    {
                        categoryId = categoryId2;
                    }
                    string categoryId3 = ddlThreeCategoryId.SelectedValue == null ? "" : ddlThreeCategoryId.SelectedValue.ToString();
                    if (!string.IsNullOrEmpty(categoryId3))
                    {
                        categoryId = categoryId3;
                    }
                    val = productAdapter.Update(
                        Convert.ToInt32(txtFitemId.Value),
                        txtProductSpecification.Value,
                        txtUserCode.Value, categoryId, "", txtpicUrl.Value, txtDescription.Value, txtProductName.Value, Convert.ToDecimal(txtPackageWidth.Value), Convert.ToDecimal(txtPackageLength.Value),
                        Convert.ToDecimal(txtPackageHeight.Value), Convert.ToDecimal(txtPackageVolume.Value), Convert.ToDecimal(txtPackageWeight.Value), Convert.ToDecimal(txtSpecial_PackageWeight.Value),
                        Convert.ToInt32(ddlIsOutOfStock.Value), Convert.ToInt32(txtSalesLevel.Value), Convert.ToInt32(ddlSalesStatus.Value), txtKeyWords.Value, string.IsNullOrEmpty(txtCheckDateTime.Value) ? new DateTime(1900, 1, 1) : Convert.ToDateTime(txtCheckDateTime.Value),
                        Convert.ToInt32(ddlPackageType.Value), Convert.ToInt32(ddlNewProductStatus.Value), Convert.ToInt32(ddlWarrantyDays.Value), txtCustomsName.Value, txtHSCode.Value, txtInternationalCode.Value,
                        Convert.ToInt32(ddlConditionId.Value), Convert.ToInt32(ddlDeliveryWarehouseId.Value), Convert.ToInt32(ddlDeliveryId.Value), Convert.ToInt32(ddlIsNew.Value),
                        string.IsNullOrEmpty(txtAddDateTime.Value) ? new DateTime(1900, 1, 1) : Convert.ToDateTime(txtAddDateTime.Value), txtDelivery.Value, Convert.ToDecimal(txtExpectedSales.Value),
                        Convert.ToDecimal(txtMinProfit.Value), txtSalesGroup.Value, Convert.ToInt32(ddlMeasureUnitsGroup.Value), Convert.ToInt32(ddlBaseUnit.Value),
                        Convert.ToInt32(ddlPurUnit.Value), Convert.ToInt32(ddlSalesUnit.Value), Convert.ToInt32(ddlProduceUnit.Value), Convert.ToInt32(ddlStoreUnit.Value), Convert.ToInt32(ddlLableUnit.Value),
                        Convert.ToInt32(ddlProductType.Value), Convert.ToInt32(ddlUseStatusId.Value), Convert.ToInt32(ddlSalesMode.Value), Convert.ToInt32(ddlValuationMethod.Value),
                        Convert.ToInt32(ddlStockSubjectId.Value), Convert.ToInt32(ddlSalesSubjectId.Value), Convert.ToInt32(ddlSalesCostSubjectId.Value), Convert.ToDecimal(txtEbayMinPrice.Value),
                        txtEbayMinPriceCountry.Value, Convert.ToDecimal(txtEbayRankMinPrice.Value), Convert.ToDecimal(txtSuggestionPurPrice.Value), Convert.ToDecimal(txtExpectedPurPrice.Value),
                        Convert.ToDecimal(txtExpectedUnitProfit.Value), Convert.ToDecimal(txtExpectedDayOfProfit.Value), string.IsNullOrEmpty(txtExpectedSalesDateTime.Value) ? new DateTime(1900, 1, 1) : Convert.ToDateTime(txtExpectedSalesDateTime.Value),
                        Convert.ToDecimal(txtExpectedWeight.Value), Convert.ToDecimal(txtExpectedPrice.Value), txtRivalItemId.Value, Convert.ToInt32(txtStockLevel.Value), Convert.ToInt32(txtMaxStockDay.Value),
                        Convert.ToDecimal(txtExpectedSalesArg.Value), Convert.ToInt32(txtOrderHandleDay.Value), Convert.ToInt32(txtAllocationDay.Value), Convert.ToDecimal(txtWareHouseSafeArg.Value),
                        Convert.ToDecimal(txtCenterWareHouseSafetyFactor.Value), Convert.ToInt32(txtCenterWareHouseReplenishmentInterval.Value),
                        Convert.ToInt32(txtCenterWareHouseShipInterval.Value), Convert.ToInt32(txtTransitDays.Value), Convert.ToInt32(txtWarningDays.Value),
                        Convert.ToInt32(txtDestWareHouse.Value), Convert.ToInt32(txtTransitWareHouse.Value), "", userId, DateTime.Now, "", new DateTime(1900, 1, 1), 0, 0m, 0m,
                        txtProductId.Value);
                    if (val > 0)
                    {
                        Response.Write("<script>alert('修改成功!');window.location.href='Product.aspx'</script>");
                    }
                }
                break;
        }

    }
    protected void btnSendK3_Click(object sender, EventArgs e)
    {
        if (Session["UserId"] == null)
        {
            WebUtility.ShowMsg("登陆超时,请重新登陆", this);
            return;
        }
        string userId = Session["UserId"].ToString();
        ebay.Model.Product productMode = new ebay.Model.Product();
        productMode.AddDateTime = DateTime.Now;
        productMode.Atime = new DateTime(1900, 1, 1);
        productMode.Auser = "";
        productMode.BaseUnit = ddlBaseUnit.Value == null ? 0 : Convert.ToInt32(ddlBaseUnit.Value.ToString());
        string categoryId = "";
        string categoryId1 = ddlFirstCategoryId.SelectedValue == null ? "" : ddlFirstCategoryId.SelectedValue.ToString();
        if (!string.IsNullOrEmpty(categoryId1))
        {
            categoryId = categoryId1;
        }
        string categoryId2 = ddlTwoCategoryId.SelectedValue == null ? "" : ddlTwoCategoryId.SelectedValue.ToString();
        if (!string.IsNullOrEmpty(categoryId2))
        {
            categoryId = categoryId2;
        }
        string categoryId3 = ddlThreeCategoryId.SelectedValue == null ? "" : ddlThreeCategoryId.SelectedValue.ToString();
        if (!string.IsNullOrEmpty(categoryId3))
        {
            categoryId = categoryId3;
        }
        productMode.CategoryId = categoryId;
        productMode.ConditionId = ddlConditionId.Value == null ? 0 : Convert.ToInt32(ddlConditionId.Value.ToString());
        productMode.CustomsName = txtCustomsName.Value;
        productMode.DeliveryId = ddlDeliveryId.Value == null ? 0 : Convert.ToInt32(ddlDeliveryId.Value.ToString());
        productMode.Delivery = txtDelivery.Value;
        productMode.Description = txtDescription.Value;
        productMode.EbayMinPrice = Convert.ToDouble(txtEbayMinPrice.Value);
        productMode.EbayMinPriceCountry = txtEbayMinPriceCountry.Value;
        productMode.EbayRankMinPrice = Convert.ToDouble(txtEbayRankMinPrice.Value);
        productMode.ExpectedPurPrice = Convert.ToDouble(txtExpectedPurPrice.Value);
        productMode.ExpectedSales = Convert.ToDecimal(txtExpectedSales.Value);
        productMode.HSCode = txtHSCode.Value;
        productMode.InternationalCode = txtInternationalCode.Value;
        productMode.StockSubjectId = ddlStockSubjectId.Value == null ? 0 : Convert.ToInt32(ddlStockSubjectId.Value.ToString());
        productMode.IsNew = ddlIsNew.Value == null ? 0 : Convert.ToInt32(ddlIsNew.Value.ToString());
        productMode.IsOutOfStock = ddlIsOutOfStock.Value == null ? 0 : Convert.ToInt32(ddlIsOutOfStock.Value.ToString());
        productMode.KeyWords = txtKeyWords.Value;
        productMode.LableUnit = ddlLableUnit.Value == null ? 0 : Convert.ToInt32(ddlLableUnit.Value.ToString());
        productMode.MinProfit = Convert.ToDecimal(txtMinProfit.Value);
        productMode.Mtime = DateTime.Now;
        productMode.Muser = userId;
        productMode.Mnote = "";
        productMode.PackageHeight = Convert.ToDecimal(txtPackageHeight.Value);
        productMode.PackageLength = Convert.ToDecimal(txtPackageLength.Value);
        productMode.PackageType = ddlPackageType.Value == null ? 0 : Convert.ToInt32(ddlPackageType.Value.ToString());
        productMode.PackageVolume = Convert.ToDecimal(txtPackageVolume.Value);
        productMode.PackageWeight = Convert.ToDecimal(txtPackageWeight.Value);
        productMode.PackageWidth = Convert.ToDecimal(txtPackageWidth.Value);
        productMode.PicUrl = "";
        productMode.ProduceUnit = ddlProduceUnit.Value == null ? 0 : Convert.ToInt32(ddlProduceUnit.Value.ToString());
        productMode.ProductId = txtProductId.Value;
        productMode.ProductName = txtProductName.Value;
        productMode.NewProductStatus = ddlNewProductStatus.Value == null ? 0 : Convert.ToInt32(ddlNewProductStatus.Value.ToString());
        productMode.ProductType = ddlProductType.Value == null ? 0 : Convert.ToInt32(ddlProductType.Value.ToString());
        productMode.PurUnit = ddlPurUnit.Value == null ? 0 : Convert.ToInt32(ddlPurUnit.Value.ToString());
        productMode.SalesCostSubjectId = ddlSalesCostSubjectId.Value == null ? 0 : Convert.ToInt32(ddlSalesCostSubjectId.Value.ToString());
        productMode.SalesGroup = txtSalesGroup.Value;
        productMode.SalesLevel = Convert.ToInt32(txtSalesLevel.Value);
        productMode.SalesMode = ddlSalesMode.Value == null ? 0 : Convert.ToInt32(ddlSalesMode.Value.ToString());
        productMode.SalesStatus = ddlSalesStatus.Value == null ? 0 : Convert.ToInt32(ddlSalesStatus.Value.ToString());
        productMode.SalesSubjectId = ddlSalesSubjectId.Value == null ? 0 : Convert.ToInt32(ddlSalesSubjectId.Value.ToString());
        productMode.SalesUnit = ddlSalesUnit.Value == null ? 0 : Convert.ToInt32(ddlSalesUnit.Value.ToString());
        productMode.Special_PackageWeight = Convert.ToDecimal(txtSpecial_PackageWeight.Value);
        productMode.StoreUnit = ddlStoreUnit.Value == null ? 0 : Convert.ToInt32(ddlStoreUnit.Value.ToString());
        productMode.SuggestionPurPrice = Convert.ToDouble(txtSuggestionPurPrice.Value);
        productMode.UserCode = txtUserCode.Value;
        productMode.UseStatusId = ddlUseStatusId.Value == null ? 0 : Convert.ToInt32(ddlUseStatusId.Value.ToString());
        productMode.ValuationMethod = ddlValuationMethod.Value == null ? 0 : Convert.ToInt32(ddlValuationMethod.Value.ToString());
        productMode.DeliveryWarehouseId = ddlDeliveryWarehouseId.Value == null ? 0 : Convert.ToInt32(ddlDeliveryWarehouseId.Value.ToString());
        productMode.WarrantyDays = ddlWarrantyDays.Value == null ? 0 : Convert.ToInt32(ddlWarrantyDays.Value.ToString());
        productMode.MeasureUnitsGroup = ddlMeasureUnitsGroup.Value == null ? 0 : Convert.ToInt32(ddlMeasureUnitsGroup.Value);
        ebay.Dal.Product p = new ebay.Dal.Product();
        p.InsertK3(productMode);

        WebUtility.ShowMsg("已成功送入K3系统", this);

    }
}
